<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------

namespace app\index\controller;

use app\common\controller\Fornt;
use app\common\model\AddressNew;
use think\Request;
use think\Cache;
/**
 * 自定义付款
 */
class Custompayment extends Fornt{

	public function index(){
		update_session(USER_ID);
    //获取默认地址
 		$address = AddressNew::get(['user_id'=>USER_ID,'defaults'=>1]);


		$data = [
			'address' =>$address,
			'custom_title' =>Cache::get('custom_title'),
			'custom_price' =>Cache::get('custom_price')
		];
		$this->assign($data);
		$this->assign('title', '自定义付款');
		return $this->fetch();
	}
	/**
	 * 编辑自定义付款内容
	 * @param  string $title [description]
	 * @param  string $price [description]
	 * @return [type]        [description]
	 */
	public function edit($title = '', $price = ''){
		if(IS_POST){
			if(empty($title)){
				$this->error('标题不能为空！');
			}
			if(!is_numeric($price) && $price >= 0){
				$this->error('金额必须大于0');
			}

			Cache::set('custom_title', $title);
			Cache::set('custom_price', $price);
			if(Cache::get('custom_title')){
				$this->success('设置成功！');
			}
		}else{

			$data = [
				'custom_title' =>Cache::get('custom_title'),
				'custom_price' =>Cache::get('custom_price')
			];
			$this->assign($data);
			return $this->fetch();
		}

	}

}
